# 导包
from api.reg import RegAPI
import random
import requests


# 创建测试类
class TestReg:
    # 初始化
    def setup_class(self):
        self.reg = RegAPI()
        # 创建session
        self.session = requests.Session()

    # 获取图片验证码成功（随机小数）
    def test01_get_img_code(self):
        response = self.reg.get_img_code(session=self.session, r="0." + str(random.randint(1, 1000)))
        assert response.status_code == 200

    # 获取短信验证码成功
    def test02_get_sms_code(self):
        test_data = {
            "phone": "13876530001",
            "imgVerifyCode": "8888",
            "type": "reg"
        }
        response = self.reg.get_sms_code(session=self.session,test_data=test_data)
        # print(response.json())
        # 断言
        assert response.status_code == 200
        assert response.json().get("status") == 200
        assert response.json().get("description") == "短信发送成功"
        assert "成功" in response.text

